package cn.xinfei.xdecision.common.service.datax.datamanage.imp;

import cn.xinfei.xdecision.common.dao.datax.datamanage.FieldMapper;
import cn.xinfei.xdecision.common.model.datax.datamanage.Field;
import cn.xinfei.xdecision.common.service.datax.datamanage.FieldService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Service
@Slf4j
public class FieldServiceImp extends ServiceImpl<FieldMapper, Field> implements FieldService {
    @Autowired
    private FieldMapper fieldMapper;

    @Override
    public List<Field> queryByEnsByCache(Collection<String> ens) {
        if (ens == null || ens.size() == 0) {
            return new ArrayList<>();
        }

        LambdaQueryWrapper<Field> lambdaQueryWrapper = new LambdaQueryWrapper<Field>();
        lambdaQueryWrapper.in(Field::getFieldCode, ens);
        return fieldMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<Field> queryByEns(Collection<String> ens) {
        if (ens == null || ens.size() == 0) {
            return new ArrayList<>();
        }

        LambdaQueryWrapper<Field> lambdaQueryWrapper = new LambdaQueryWrapper<Field>();
        lambdaQueryWrapper.in(Field::getFieldCode, ens);
        return fieldMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<Field> selectFieldListByEns(List<String> fieldEnList) {
        LambdaQueryWrapper<Field> lambdaQueryWrapper = new LambdaQueryWrapper<Field>();
        lambdaQueryWrapper.in(Field::getFieldCode, fieldEnList);
        return fieldMapper.selectList(lambdaQueryWrapper);
    }

}
